package com.cy.sentinel授权黑白名单的配置类;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/*Sentinel的白名单放行*/
@Component //必须加@Component注解，整个类交给spring管理
public class DefaultRequestOriginParser implements RequestOriginParser {
    //http://ip:port/path?origin=echo
    @Override
    public String parseOrigin(HttpServletRequest request) {
        //1.基于url中的参数进行限流(Sentinel--授权--流控应用：(origin=)abcd--白名单--只有输入它才能访问：http://localhost:8090/consumer/doRestEcho?origin=abcd)
//String origin=request.getParameter("origin");
//return origin;

        //2.基于ip地址进行限流(Sentinel--授权--流控应用：127.0.0.1--黑名单--http://127.0.0.1:8090/consumer/doRestEcho 不能用127.0.0.1地址访问了)
        String remoteAddr = request.getRemoteAddr();
        System.out.println("remoteAddr=" + remoteAddr);
        return remoteAddr;
    }
}
